package cn.akwangl.concurrency.web.model.items.service.impl;

import cn.akwangl.concurrency.web.common.enums.YesOrNO;
import cn.akwangl.concurrency.web.model.items.mapper.ItemsImgMapper;
import cn.akwangl.concurrency.web.model.items.pojo.ItemsImgEntity;
import cn.akwangl.concurrency.web.model.items.service.ItemsImgService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 商品图片  服务实现类
 * </p>
 *
 * @author 阿坤同学
 * @since 2022-11-22 14:30:33
 */
@Service
public class ItemsImgServiceImpl extends ServiceImpl<ItemsImgMapper, ItemsImgEntity> implements ItemsImgService {

    @Override
    public Map<String, ItemsImgEntity> getItemsImgEntityIsMainMap(List<String> itemIds) {
        Map<String, ItemsImgEntity> resultMap = new HashMap(itemIds.size());

        LambdaQueryWrapper<ItemsImgEntity> lambdaQuery = Wrappers.lambdaQuery();
        lambdaQuery.in(ItemsImgEntity::getItemId, itemIds)
                .eq(ItemsImgEntity::getIsMain, YesOrNO.YES.type);
        List<ItemsImgEntity> itemsImgEntities = list(lambdaQuery);
        if (itemsImgEntities != null && !itemsImgEntities.isEmpty()) {
            for (ItemsImgEntity itemsImgEntity : itemsImgEntities) {
                String mapKey = itemsImgEntity.getItemId();
                ItemsImgEntity mapValue = itemsImgEntity;
                resultMap.put(mapKey, mapValue);
            }
        }
        return resultMap;
    }
}
